import { widgetTool } from './widgetTools'

const screenConfig = {
  code: 'screen',
  type: 'screen',
  label: '大屏设置',
  icon: '',
  presetLine: [
    { type: 'h', site: 100 },
    { type: 'v', site: 200 }
  ],
  options: {
    setup: {
      width: 1920,
      height: 1080,
      name: '',
      description: '',
      backgroundColor: '#1E1E1E',
      backgroundImage: ''
    }
  }
}

export const converArr = (data) => {
  const tempArr: any[] = [],
    newArr: any[] = []
  for (let i = 0; i < data.length; i++) {
    const item = data[i]
    item.widgetId = ''
    if (tempArr.indexOf(item.type) === -1) {
      newArr.push({
        name: item.tabName,
        type: item.type,
        list: [item]
      })
      tempArr.push(item.type)
    } else {
      for (let j = 0; j < newArr.length; j++) {
        if (newArr[j].type == item.type) {
          newArr[j].list.push(item)
        }
      }
    }
  }
  return newArr
}

const widgetTools = converArr(widgetTool)

const getToolByCode = function (code) {
  // 获取大屏底层设置属性
  if (code == 'screen') {
    return screenConfig
  }
  // 获取组件
  return [...widgetTool].find((item) => {
    return item.code == code
  })
}
export { widgetTools, getToolByCode }
